// pages/search/index.js
import {request} from "../../request/index.js"
Page({
  onShow:function (){
    // this.getGoodsearch();
  },
  /**
   * 页面的初始数据
   */
  data: {
    // 获取的结果
    results:[],
    isfous:false,
  },
  searchId:-1,
  searchInput(e){
    // 获取输入框的值
      let value = e.detail.value;
    // console.log(e.detail.value)
    if(!value.trim()){
      this.setData({
        isfous:false,
        results:[],
        inputValue:""
      })
      // console.log("值不合法")
      return;
    }
    this.setData({
      isfous:true
    })
    clearTimeout(this.searchId);
      this.searchId = setTimeout(()=>{
      this.getGoodsearch(value);
    },1000)
  },
  getGoodsearch(value){
    request({url: '/goods/search?query='+value}).then(result=>{
    //  console.log(result.data.message.goods)
      this.setData({
        results:result.data.message.goods
      })
    })
  },
  xiaoshi(){
    this.setData({
      isfous:false,
        results:[],
        inputValue:""
    })
  }
  
})